//
//  MLBleHelp.m
//  RuZe
//
//  Created by 程杰 on 2023/5/31.
//

#import "MLBleHelp.h"
#import <SystemConfiguration/CaptiveNetwork.h>
#import <CoreLocation/CoreLocation.h>

@interface MLBleHelp()
@property (nonatomic,strong) CLLocationManager *manager;
@end

@implementation MLBleHelp

- (instancetype)init {
    if (self = [super init]) {
        [self checkOpenLocationOrNot];
    }
    return self;
}

//判断是否开启了地理位置信息
- (BOOL)checkOpenLocationOrNot
{
    CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
    if (kCLAuthorizationStatusDenied == status || kCLAuthorizationStatusRestricted == status || kCLAuthorizationStatusNotDetermined == status) {
        
        self.manager = [[CLLocationManager alloc]init];
        [self.manager requestAlwaysAuthorization];
        
        return NO;
    }
    return YES;
}
//判断iOS13根据地理位置返回能否返回WiFiSSid
- (BOOL)canGetWifiSSid {
    if (@available(iOS 13.0, *)) {
        return [self checkOpenLocationOrNot];
    }
    return YES;
}

+ (NSString *)getSSID {
    return [[[MLBleHelp alloc]init] getWifiInfo][@"SSID"];
}

-(NSDictionary*)getWifiInfo{
    
    CFArrayRef wifiInterfaces = CNCopySupportedInterfaces();
    
    if (!wifiInterfaces) {
        return nil;
    }
    
    NSArray *interfaces = (__bridge NSArray *)wifiInterfaces;
    
    for (NSString *interfaceName in interfaces) {
        CFDictionaryRef dictRef = CNCopyCurrentNetworkInfo((__bridge CFStringRef)(interfaceName));
        
        if (dictRef) {
            NSDictionary *networkInfo = (__bridge NSDictionary *)dictRef;
            NSLog(@"network info -> %@", networkInfo);
            
            return networkInfo;
        }
    }
    
    return nil;
}

@end
